/*
 * Copyright 2016 Yan Zhenjie
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mingmen.supplier.activity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.mingmen.supplier.R;
import com.mingmen.supplier.defineview.GlideRoundTransform;
import com.mingmen.supplier.httpconfig.AppConfig;
import com.mingmen.supplier.model.EvalListModel;
import com.mingmen.supplier.ratingbar.RotationRatingBar;
import com.mingmen.supplier.util.GsonUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;


/**
 * <p>
 * ListView形式的侧滑菜单，支持横向和竖向的。
 * </p>
 * Created by Yan Zhenjie on 2016/7/27.
 */
public class PingScoreActivity extends Activity {

    private static final String TAG = "PingScoreActivity";
    String str_Score;
    String getStr_Score;
    @BindView(R.id.img_qualityScore)
    ImageView img_qualityScore;
    int qualityScore;
    int packageScore;
    int serviceScore;
    @BindView(R.id.img_packageScore)
    ImageView img_packageScore;
    @BindView(R.id.img_serviceScore)
    ImageView img_serviceScore;
    @BindView(R.id.mark)
    TextView mark;
    @BindView(R.id.btn_close)
    Button btn_close;
    @BindView(R.id.ivAvatar)
    ImageView ivAvatar;
    Context mContext;
    int allScore;
    @BindView(R.id.img_scorebck)
    ImageView img_scorebck;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pingscore);
        EventBus.getDefault().register(this);
        ButterKnife.bind(this);
        mContext = this;
        final RotationRatingBar baseRatingBar = findViewById(R.id.star_one);

        baseRatingBar.setClearRatingEnabled(false);
        baseRatingBar.setOnRatingChangeListener((ratingBar, rating, fromUser) -> Log
                .d(TAG, "BaseRatingBar onRatingChange: " + rating));
        str_Score = getIntent().getStringExtra("str_Score");


        getStr_Score = getIntent().getStringExtra("getStr_Score");
        str_Score = str_Score.substring(1, str_Score.length() - 1);
        EvalListModel evalListModel = new EvalListModel();
        Log.d("str_Score", str_Score);
        Log.d("getStr_Score", getStr_Score);
        Log.d("dkdkdkdk",str_Score);

        evalListModel = GsonUtil.GsonToBean(str_Score, EvalListModel.class);
        try {
            mark.setText(evalListModel.getMark());
        }catch (Exception e){
            mark.setText("");
        }

        qualityScore = evalListModel.getQualityScore();
        packageScore = evalListModel.getPackageScore();
        serviceScore = evalListModel.getServiceScore();
        allScore = qualityScore + packageScore + serviceScore;
        if (allScore > 7) {
            img_scorebck.setImageResource(R.mipmap.haoping);
        }else {
            img_scorebck.setImageResource(R.mipmap.chaping);
        }

        Glide.with(mContext).load(AppConfig.IMGURL + evalListModel.getPicture()).dontAnimate().placeholder(R.mipmap.zhanwei).error(R.mipmap.zhanwei).transform(new GlideRoundTransform(mContext, 5)).into(ivAvatar);
        if (qualityScore == 1) {
            img_qualityScore.setImageResource(R.mipmap.star_one);
        } else if (qualityScore == 2) {
            img_qualityScore.setImageResource(R.mipmap.star_two);
        } else if (qualityScore == 3) {
            img_qualityScore.setImageResource(R.mipmap.star_three);
        } else if (qualityScore == 4) {
            img_qualityScore.setImageResource(R.mipmap.star_fourth);
        } else if (qualityScore == 5) {
            img_qualityScore.setImageResource(R.mipmap.star_fifth);
        }


        if (packageScore == 1) {
            img_packageScore.setImageResource(R.mipmap.star_one);
        } else if (packageScore == 2) {
            img_packageScore.setImageResource(R.mipmap.star_two);
        } else if (packageScore == 3) {
            img_packageScore.setImageResource(R.mipmap.star_three);
        } else if (packageScore == 4) {
            img_packageScore.setImageResource(R.mipmap.star_fourth);
        } else if (packageScore == 5) {
            img_packageScore.setImageResource(R.mipmap.star_fifth);
        }


        if (serviceScore == 1) {
            img_serviceScore.setImageResource(R.mipmap.star_one);
        } else if (serviceScore == 2) {
            img_serviceScore.setImageResource(R.mipmap.star_two);
        } else if (serviceScore == 3) {
            img_serviceScore.setImageResource(R.mipmap.star_three);
        } else if (serviceScore == 4) {
            img_serviceScore.setImageResource(R.mipmap.star_fourth);
        } else if (serviceScore == 5) {
            img_serviceScore.setImageResource(R.mipmap.star_fifth);
        }

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();

    }

    @OnClick({R.id.btn_close})
    public void onViewClicked(View view) {
        switch (view.getId()) {

            case R.id.btn_close:
                finish();
                break;
        }
    }

    public void onEventMainThread(Integer type) {

    }
}